home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / docs / linux-do / programm / lpg-0.4 / lpg-0 / LPG / examples / ipc / popen1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-01  |  841 b   |  37 lines

  1. /*****************************************************************************
  2.  Excerpt from "Linux Programmer's Guide - Chapter 6"
  3.  (C)opyright 1994-1995, Scott Burkett
  4.  ***************************************************************************** 
  5.  MODULE: popen1.c
  6.  *****************************************************************************/
  7.   
  8. #include <stdio.h>
  9.  
  10. #define MAXSTRS 5
  11.  
  12. int main(void)
  13. {
  14.     int  cntr;
  15.     FILE *pipe_fp;
  16.     char *strings[MAXSTRS] = { "echo", "bravo", "alpha",
  17.                           "charlie", "delta"};
  18.  
  19.     /* Create one way pipe line with call to popen() */
  20.     if (( pipe_fp = popen("sort", "w")) == NULL)
  21.     {
  22.         perror("popen");
  23.         exit(1);
  24.     }
  25.  
  26.     /* Processing loop */
  27.     for(cntr=0; cntr<MAXSTRS; cntr++) {
  28.         fputs(strings[cntr], pipe_fp);
  29.         fputc('\n', pipe_fp);
  30.     }
  31.  
  32.     /* Close the pipe */
  33.     pclose(pipe_fp);
  34.     
  35.     return(0);
  36. }
  37.